/*

Author   : chaos

FileName : asign_overloading.cpp

Date     : 12/08/17 17:07:29

*/
#include <iostream>
#include <cstring>
using namespace std;

class String
{
    private:
        char * string;
        long len;
    public:
        String();
        String(const char *);
        void show_string();
        String & operator = (const String &);
};

void String::show_string()
{
    cout << "string :" << string << " string address :";
    cout << (void *)string;

    cout << "length :" << len << endl;

}

String::String()
{
    len = 0;
    string = new char[len + 1];
    string[0] = '\0';
}

String::String(const char * i_string)
{
    len = strlen(i_string);
    string = new char[len + 1];
    strcpy(string,i_string);
}

String & String:: operator= (const String & str)
{
    cout << "overloading operator " << endl;
    delete string;

    len = str.len;
    string = new char[len + 1];
    strcpy(string,str.string);

    return * this;
}


int main(int argc ,char *argv[])
{
    String A_String("My string");
    String B_String;

    B_String = A_String;

    cout << "A_String ..." << endl;
    A_String.show_string();

    cout << "B_String >>>" << endl;
    B_String.show_string();
    return 0;
}
